package com.sheep.jucdemo.part1.part1_11;

/**
 * @Date 2022/4/10 23:21
 * @Created by sheep
 */
public class Test1_11_4 {
    public static ThreadLocal<String> threadLocal = new InheritableThreadLocal<String>();

    public static void main(String[] args) {
        // 设置现场变量值
        threadLocal.set("hello world");
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                // 子线程输出现场变量的值
                System.out.println("thread: " + threadLocal.get());
            }
        });
        // 启动子线程
        thread.start();
        // 主线程输出线程变量的值
        System.out.println("main: " + threadLocal.get());
    }
}
